﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 工艺流程步骤-加工过程(工序)
    /// </summary>
    public partial class CraftStepProcess : BusEntity
    {
        /// <summary>
        /// 工艺流程步骤ID
        /// </summary>
        public string CraftStepId { set; get; }
        /// <summary>
        /// 工序编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 下一工序编码
        /// </summary>
        public string NextProcessCode { set; get; }
        /// <summary>
        /// 工序名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 工序图标
        /// </summary>
        public string Icon { set; get; }
        /// <summary>
        /// 排序号
        /// </summary>
        public int Sort { set; get; }
    }

    public partial class CraftStepProcess : BusEntity
    {
        public CraftStep Step { set; get; }
        /// <summary>
        /// 加工工序下的工作
        /// </summary>
        public List<WorkshoStation> Stations { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class CraftStepProcessTypeConfig : BusEntityTypeConfig<CraftStepProcess>, IEntityTypeConfiguration<CraftStepProcess>
    {
        public override void Configure(EntityTypeBuilder<CraftStepProcess> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Step).WithMany(p => p.Process).HasForeignKey(p => p.CraftStepId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.CraftStepId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();            
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.NextProcessCode).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Icon).HasMaxLength(EntityDefinition.DefSmallColLen);
            #endregion

            #region 备注
            builder.HasComment("工艺流程步骤-加工过程(工序)");
            builder.Property(p => p.CraftStepId).HasComment("工艺流程步骤ID");            
            builder.Property(p => p.Code).HasComment("工序编码");
            builder.Property(p => p.NextProcessCode).HasComment("下一工序编码");
            builder.Property(p => p.Name).HasComment("工序名称");
            builder.Property(p => p.Icon).HasComment("工序图标");
            #endregion

            #region 种子数据
            builder.HasData(new CraftStepProcess() { Id = "1001001", Code = "1001001", NextProcessCode = "1004003", CraftStepId= "1001", Name = "叶片分拣", Icon = "dropbox", Sort = 11, CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new CraftStepProcess() { Id = "1001002", Code = "1001002", NextProcessCode = "1002001", CraftStepId = "1001", Name = "前锥板分拣", Icon = "dropbox", Sort = 12, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1001003", Code = "1001003", NextProcessCode = "1002002", CraftStepId = "1001", Name = "后锥前板分拣", Icon = "dropbox", Sort = 13, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1001004", Code = "1001004", NextProcessCode = "1002003", CraftStepId = "1001", Name = "后锥后板分拣", Icon = "dropbox", Sort = 14, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1001005", Code = "1001005", NextProcessCode = "1002007", CraftStepId = "1001", Name = "中筒板分拣", Icon = "dropbox", Sort = 15, CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new CraftStepProcess() { Id = "1002001", Code = "1002001", NextProcessCode = "1002004", CraftStepId = "1002", Name = "前锥拼焊", Icon = "dropbox", Sort = 21, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1002002", Code = "1002002", NextProcessCode = "1002005", CraftStepId = "1002", Name = "后锥前拼焊", Icon = "dropbox", Sort = 22, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1002003", Code = "1002003", NextProcessCode = "1002006", CraftStepId = "1002", Name = "后锥后拼焊", Icon = "dropbox", Sort = 23, CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new CraftStepProcess() { Id = "1002004", Code = "1002004", NextProcessCode = "1003001", CraftStepId = "1002", Name = "前锥卷圆", Icon = "dropbox", Sort = 24, CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new CraftStepProcess() { Id = "1002005", Code = "1002005", NextProcessCode = "1003002", CraftStepId = "1002", Name = "后锥前卷圆", Icon = "dropbox", Sort = 25, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1002006", Code = "1002006", NextProcessCode = "1003003", CraftStepId = "1002", Name = "后锥后卷圆", Icon = "dropbox", Sort = 26, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1002007", Code = "1002007", NextProcessCode = "1003004", CraftStepId = "1002", Name = "中筒卷圆", Icon = "dropbox", Sort = 27, CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new CraftStepProcess() { Id = "1003001", Code = "1003001", NextProcessCode = "1003005", CraftStepId = "1003", Name = "前锥纵缝焊接", Icon = "dropbox", Sort = 31, CreateUserId = "1", ModifyUserId = "1" });            
            builder.HasData(new CraftStepProcess() { Id = "1003002", Code = "1003002", NextProcessCode = "1003006", CraftStepId = "1003", Name = "后锥前纵缝焊接", Icon = "dropbox", Sort = 32, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1003003", Code = "1003003", NextProcessCode = "1003007", CraftStepId = "1003", Name = "后锥后纵缝焊接", Icon = "dropbox", Sort = 33, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1003004", Code = "1003004", NextProcessCode = "1004001", CraftStepId = "1003", Name = "中筒纵缝焊接", Icon = "dropbox", Sort = 34, CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new CraftStepProcess() { Id = "1003005", Code = "1003005", NextProcessCode = "1004001", CraftStepId = "1003", Name = "前锥组对", Icon = "dropbox", Sort = 35, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1003006", Code = "1003006", NextProcessCode = "1004001", CraftStepId = "1003", Name = "后锥前压工装", Icon = "dropbox", Sort = 36, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1003007", Code = "1003007", NextProcessCode = "1004005", CraftStepId = "1003", Name = "后锥后压滚道", Icon = "dropbox", Sort = 37, CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new CraftStepProcess() { Id = "1004001", Code = "1004001", NextProcessCode = "1004002", CraftStepId = "1004", Name = "立式组对", Icon = "dropbox", Sort = 41, CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new CraftStepProcess() { Id = "1004002", Code = "1004002", NextProcessCode = "1004003", CraftStepId = "1004", Name = "内环缝焊", Icon = "dropbox", Sort = 42, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1004003", Code = "1004003", NextProcessCode = "1004004", CraftStepId = "1004", Name = "叶片摆搭", Icon = "dropbox", Sort = 43, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1004004", Code = "1004004", NextProcessCode = "1004005", CraftStepId = "1004", Name = "叶片螺旋焊", Icon = "dropbox", Sort = 44, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1004005", Code = "1004005", NextProcessCode = "1004006", CraftStepId = "1004", Name = "筒体合模", Icon = "dropbox", Sort = 45, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1004006", Code = "1004006", NextProcessCode = "1004007", CraftStepId = "1004", Name = "外环缝焊", Icon = "dropbox", Sort = 46, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new CraftStepProcess() { Id = "1004007", Code = "1004007", NextProcessCode = "1005001", CraftStepId = "1004", Name = "人工补焊", Icon = "dropbox", Sort = 47, CreateUserId = "1", ModifyUserId = "1" });
            
            builder.HasData(new CraftStepProcess() { Id = "1005001", Code = "1005001", NextProcessCode = "", CraftStepId = "1005", Name = "筒体检测", Icon = "dropbox", Sort = 51, CreateUserId = "1", ModifyUserId = "1" });
            #endregion
        }
    }
}
